/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pgentity.services;

import pgentity.Mail2;
import pgentity.Mail3;
import pgentity.Mailbox3;
import pgentity.User;
import share.PGHelper;

/**
 *
 * @author KieuAnh
 */
public class MailServices {
    private MailServices()
    {
        super();
    }
    
    private static final MailServices inst = new MailServices();
    
    public static MailServices inst()
    {
        return inst;
    }
    
    private static final String SYSTEM_ID = "0";
//    private void systemSendMail(String to, String content, long now)
//    {
//        Mailbox.sendMail(to, SYSTEM_ID, content, now);
//    }
    
    public void sendStealEggMail(User thief, String stolenUser, String eggKind,
            long now)
    {
        
//        V1
//        String content = String.format(
//                  "<text color=\"0xffffff\">"
//                +   "<link type=\"user\" data=\"%s\">%s</link>"
//                + "</text>"
//                + "<text> vừa trộm của bạn 1 trứng </text>"
//                + "<img src=\"%s\" />",
//                thief.getUid(), thief.getName(), eggKind);
//        this.systemSendMail(stolenUser, content, now);
        
//          V2
//        Mailbox2.sendMail(stolenUser, SYSTEM_ID,
//                Mail2.MailType.StealEgg,
//                PGHelper.toInt(thief.getUid()), 0,
//                eggKind, null, thief.getName(),
//                null, now);
        
        // V3
        Mail3 mail3 = new Mail3(Mail3.MailType.StealEgg, SYSTEM_ID, now,
                thief.getUid(), thief.getName(), eggKind);
        Mailbox3.sendMail(stolenUser, mail3);
    }
    
    public void sendHelpFishMail(User helper, String helped, int nFish,
            long now)
    {
//        String content = String.format(
//                  "<text color=\"0xffffff\">"
//                +   "<link type=\"user\" data=\"%s\">%s</link>"
//                + "</text>"
//                + "<text> vừa giúp bạn %d cá </text>",
//                helper.getUid(), helper.getName(), nFish);
//        this.systemSendMail(helped, content, now);
        
        // V2
//        Mailbox2.sendMail(helped, SYSTEM_ID,
//                Mail2.MailType.HelpFish,
//                PGHelper.toInt(helper.getUid()), nFish,
//                null, null, helper.getName(),
//                null, now);
        
        // V3
        Mail3 mail3 = new Mail3(Mail3.MailType.HelpFish, SYSTEM_ID, now,
                helper.getUid(), helper.getName(), String.valueOf(nFish));
        Mailbox3.sendMail(helped, mail3);
    }
    
    public void sendBuildSnowman(User helper, String helped, long now)
    {
//        String content = String.format(
//                  "<text color=\"0xffffff\">"
//                +   "<link type=\"user\" data=\"%s\">%s</link>"
//                + "</text>"
//                + "<text> vừa giúp bạn xây người tuyết! </text>",
//                helper.getUid(), helper.getName());
//        this.systemSendMail(helped, content, now);
        
        // V2
//        Mailbox2.sendMail(helped, SYSTEM_ID,
//                Mail2.MailType.BuildSnowman,
//                PGHelper.toInt(helper.getUid()), 0,
//                null, null, helper.getName(),
//                null, now);
        
        Mail3 mail3 = new Mail3(Mail3.MailType.BuildSnowman, SYSTEM_ID, now,
                helper.getUid(), helper.getName());
        Mailbox3.sendMail(helped, mail3);
    }
}